﻿using AntdUI;

namespace TestPressure
{
    public partial class BaseForm : AntdUI.Window
    {
        #region

        /// <summary>公共标题栏
        /// 方便修改标题
        /// </summary>
        public PageHeader Header { get; set; }

        /// <summary>是否允许移动
        /// 
        /// </summary>
        public bool EnableMove { get; set; }

        /// <summary>是否全屏
        /// 
        /// </summary>
        public bool FullScreen { get; set; }

        #endregion

        #region 自定义方法

        /// <summary>窗口禁止调整大小
        /// 
        /// </summary>
        /// <param name="m"></param>
        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            if (!this.EnableMove)
            {
                if (m.Msg == 0x112)
                {
                    switch ((int)m.WParam)
                    {
                        //禁止双击标题栏关闭窗体
                        case 0xF063:
                        case 0xF093:
                            m.WParam = IntPtr.Zero;
                            break;

                        //禁止拖拽标题栏还原窗体
                        case 0xF012:
                        case 0xF010:
                            m.WParam = IntPtr.Zero;
                            break;

                        //禁止双击标题栏
                        case 0xf122:
                            m.WParam = IntPtr.Zero;
                            break;

                        //允许关闭按钮
                        case 0xF060:
                            //m.WParam = IntPtr.Zero;
                            break;

                        //允许最大化按钮
                        case 0xf020:
                            //m.WParam = IntPtr.Zero;
                            break;

                        //允许最小化按钮
                        case 0xf030:
                            //m.WParam = IntPtr.Zero;
                            break;

                        //禁用还原按钮
                        case 0xf120:
                            //m.WParam = IntPtr.Zero;
                            break;

                        default:
                            //m.WParam = IntPtr.Zero;
                            break;
                    }
                }
                base.WndProc(ref m);
            }
        }

        /// <summary>Info消息
        /// 
        /// </summary>
        /// <param name="msg"></param>
        public void Info(string msg)
        {
            this.Invoke(new MethodInvoker(delegate
            {
                AntdUI.Message.info(this, msg);
            }));
        }


        /// <summary>Warn消息
        /// 
        /// </summary>
        /// <param name="msg"></param>
        public void Warn(string msg)
        {
            this.Invoke(new MethodInvoker(delegate
            {
                AntdUI.Message.warn(this, msg);
            }));
        }

        /// <summary>Error消息
        /// 
        /// </summary>
        /// <param name="msg"></param>
        public void Error(string msg)
        {
            this.Invoke(new MethodInvoker(delegate
            {
                AntdUI.Message.error(this, msg);
            }));
        }

        #endregion

        #region 系统方法
        public BaseForm()
        {
            InitializeComponent();
            this.Header = this.Head;
            this.Resizable = false;
        }

        private void BaseForm_Load(object sender, EventArgs e)
        {
            if (this.FullScreen)
            {
                this.StartPosition = FormStartPosition.Manual;
                Screen primaryScreen = Screen.PrimaryScreen;
                this.MaximizedBounds = primaryScreen.WorkingArea;
                this.MinimumSize = primaryScreen.WorkingArea.Size;
                this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            }
            else
            {
                this.StartPosition = FormStartPosition.CenterScreen;
            }
        }
        #endregion
    }
}
